package zaijiansunwukong;

import zaijiansunwukong.util.FileUtil;
import zaijiansunwukong.util.ImageUtils;
import zaijiansunwukong.util.PdfUtils;


/**
 * html转图片，再转pdf
 *
 * @author
 * @date 2024/11/26 14:07
 * @description: 详细说明
 */
public class HtmlToImageThenPdf {
    public static void main(String[] args) {
         String htmlStr = "\t<div style=\"height: 500px;width: 500px;background: #aee0ff;\">\n" +
                "\t\t这个是一个div\n" +
                "\t\t<h1>标题</h1>\n" +
                "\t\t<ol>\n" +
                "\t\t\t<li>a</li>\n" +
                "\t\t</ol>\n" +
                "\t\t<img style=\"margin-left: 1500px;\" width=\"300px\" height=\"200px\" " +
                 "\t\t\t\t src=\"https://inews.gtimg.com/newsapp_bt/0/11911825373/1000\">\n" +
                "\t</div>";

        try {
            //得到字节
            byte[] imageBytes = ImageUtils.htmlToImage(htmlStr);
            FileUtil.localBufferWrite(imageBytes, "E:\\javaWorkspace\\freemarker-html2pdf\\freemarker-html2pdf\\HtmlToImageThenPdf.png");
            byte[] pdfBytes = PdfUtils.imageToPdf(imageBytes, 500, 150);
            FileUtil.localBufferWrite(pdfBytes, "E:\\javaWorkspace\\freemarker-html2pdf\\freemarker-html2pdf\\HtmlToImageThenPdf.pdf");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
